import time

f = open("D:/测试.txt", "r", encoding="UTF-8")
print(type(f))

# print(f"读取5个字节的结果：{f.read(5)}")
# print(f"读取全部结果：{f.read()}")
# print("--------------------------------")

# 读取文件 - readlines()
lines = f.readlines()
print(f"lines对象的类型是：{type(lines)}")
print(f"lines对象的内容是：{lines}")

# 读取文件 - readline()
line1 = f.readline()
line2 = f.readline()
line3 = f.readline()
print(f"第一行数据是：{line1}")
print(f"第二行数据是：{line2}")
print(f"第三行数据是：{line3}")

# for循环读取文件行
for line in f:
    print(f"每一行数据:{line}")

# 文件关闭
time.sleep(10)
f.close()

# with open 语法操作文件
with open("D:/测试.txt", "r", encoding="UTF-8") as f:
     for line in f:
         print(f"每一行数据:{line}")
